<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>rem布局</title>
</head>
<body>
    <div class="main">
        <div class="demo"></div>
    </div>
</body>

<script>

   window.onresize=function(){
    //document对象是文档的根节点，每张网页都有自己的document对象只要浏览器开始载入 HTML 文档，该对象就存在了，可以直接使用
    console.log(document)
    console.log(document.documentElement.clientWidth)
    // 获取html的dom
    let htmlDom = document.getElementsByTagName('html')[0];
    htmlDom.style.fontSize = document.documentElement.clientWidth / 15 + 'px';
    console.log(htmlDom.style.fontSize);
   }

</script> 

<style>
    .demo{
        width: 1rem;
        height: 10rem;
        background-color: antiquewhite;
    }
</style>


</html>